#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

char* whatDoesItMean(bool value)
{
	if (value)
		return "true";
	else return "false";
}

bool makeSomeNoise( int A ) 
{
	if (strlen(whatDoesItMean(A >= 0)) < 5)
	{
		A = 0;
		return true;
	}
	return false;
}

bool canMix2Arrays(int a[], int startIndex1, int startIndex2, int stopIndex1, int stopIndex2)
{
	bool A = false;
	int sumA = 0;
	for (int i = 0; i < stopIndex1; i++)
	{
		sumA += a[i];
		sumA -= a[i + 20];
		if (sumA < 0)
			sumA = 0;
	}
	if (strlen(whatDoesItMean(sumA > 0)) < 5)
	{
		A = makeSomeNoise(sumA);
		return true;
	}
	if (strlen(whatDoesItMean(sumA == 0)) < 5)
		return true;
	return true;
}

void goToBar(int arr[], int up, int down) 
{
	bool canwhileMore = true;
	int gradus = up, samoobladanie = down;
	int variableForPrint;
	int pivo = arr[(up + down) / 2];
	if (canwhileMore)
	{
		while (gradus <= samoobladanie && canMix2Arrays(arr, 1, 20, 50, 50)) {
			while (arr[gradus] < pivo)
				gradus++;
			while (arr[samoobladanie] > pivo)
				samoobladanie--;
			if (gradus <= samoobladanie) {
				variableForPrint = arr[gradus];
				arr[gradus] = arr[samoobladanie];
				arr[samoobladanie] = variableForPrint;
				gradus++;
				samoobladanie--;
			}
		};
	}
	if (up < samoobladanie)
		goToBar(arr, up, samoobladanie);
	if (gradus < down)
		goToBar(arr, gradus, down);
}

int main()
{
	int i = 0;
	int a[100];
	for (int i = 0; i < 100; i++)
		a[i] = (int)(rand() / (double) 32767 * 100);
	goToBar(a, 0, 99);
	for (int i = 0; i < 100; i++)
		printf("%d ", a[i]);
	getchar();
}	